package com.ruoyi.iptv.nva.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.iptv.nva.domain.IptvNva;
import com.ruoyi.iptv.nva.service.IIptvNvaService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 分类导航Controller
 * 
 * @author 玉念聿辉
 * @date 2021-10-20
 */
@Controller
@RequestMapping("/nva/nva")
public class IptvNvaController extends BaseController
{
    private String prefix = "nva/nva";

    @Autowired
    private IIptvNvaService iptvNvaService;

    @RequiresPermissions("nva:nva:view")
    @GetMapping()
    public String nva()
    {
        return prefix + "/nva";
    }

    /**
     * 查询分类导航列表
     */
    @RequiresPermissions("nva:nva:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(IptvNva iptvNva)
    {
        startPage();
        List<IptvNva> list = iptvNvaService.selectIptvNvaList(iptvNva);
        return getDataTable(list);
    }

    /**
     * 导出分类导航列表
     */
    @RequiresPermissions("nva:nva:export")
    @Log(title = "分类导航", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(IptvNva iptvNva)
    {
        List<IptvNva> list = iptvNvaService.selectIptvNvaList(iptvNva);
        ExcelUtil<IptvNva> util = new ExcelUtil<IptvNva>(IptvNva.class);
        return util.exportExcel(list, "分类导航数据");
    }

    /**
     * 新增分类导航
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存分类导航
     */
    @RequiresPermissions("nva:nva:add")
    @Log(title = "分类导航", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(IptvNva iptvNva)
    {
        return toAjax(iptvNvaService.insertIptvNva(iptvNva));
    }

    /**
     * 修改分类导航
     */
    @GetMapping("/edit/{nvaId}")
    public String edit(@PathVariable("nvaId") Long nvaId, ModelMap mmap)
    {
        IptvNva iptvNva = iptvNvaService.selectIptvNvaByNvaId(nvaId);
        mmap.put("iptvNva", iptvNva);
        return prefix + "/edit";
    }

    /**
     * 修改保存分类导航
     */
    @RequiresPermissions("nva:nva:edit")
    @Log(title = "分类导航", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(IptvNva iptvNva)
    {
        return toAjax(iptvNvaService.updateIptvNva(iptvNva));
    }

    /**
     * 删除分类导航
     */
    @RequiresPermissions("nva:nva:remove")
    @Log(title = "分类导航", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(iptvNvaService.deleteIptvNvaByNvaIds(ids));
    }
}
